

let Action = require('./action');

// 注意 这里是 ScaleBy 继承  ScaleTo
class ScaleTo extends Action{
    constructor(duration,sx,sy) {
        super();
        this.duration = duration;
        this._dstSx = sx;
        this._dstSy = sy;
    }

    start() {
        super.start();
        this._stSx = this.target.sx;
        this._stSy = this.target.sy;
        this._dsx = this._dstSx - this._stSx;
        this._dsy = this._dstSy - this._stSy;
    }

    update(t) {
        if(this.target.visible && this.target.enabled){
            this.target.sx = this._stSx + t * this._dsx;
            this.target.sy = this._stSy + t * this._dsy;
        }
    }
}

class ScaleBy extends ScaleTo{
    constructor(duration,sx,sy) {
        super(duration,sx,sy);
    }

    start() {
        super.start();
        this._dsx = this.target.sx * this._dstSx -  this._stSx;
        this._dsy = this.target.sy * this._dstSy -  this._stSy;
    }

    update(t) {
        if(this.target.visible && this.target.enabled){
            this.target.sx = this._stSx + t * this._dsx;
            this.target.sy = this._stSy + t * this._dsy;
        }
    }
}

module.exports = {
    ScaleTo:ScaleTo,
    ScaleBy:ScaleBy
};